package com.qianyanglong.m3u8.model;

import com.qianyanglong.m3u8.vo.M3U8VO;

import javax.swing.event.TableModelListener;
import javax.swing.table.TableModel;
import java.util.ArrayList;
import java.util.List;

public class M3U8TableModel implements TableModel {

    private String[] columnNames;

    private Class[] columnClass;

    private Object[][] data;

    private List<M3U8VO> m3U8VOList;

    public M3U8TableModel(String[] columnNames){
        this.columnNames = columnNames;
        this.m3U8VOList = new ArrayList<>();
    }

    @Override
    public int getRowCount() {
        return m3U8VOList.size();
    }

    @Override
    public int getColumnCount() {
        return columnNames.length;
    }

    @Override
    public String getColumnName(int columnIndex) {
        return columnNames[columnIndex];
    }

    @Override
    public Class<?> getColumnClass(int columnIndex) {
        if(columnClass.length<columnIndex-1){
            return String.class;
        }
        return columnClass[columnIndex];
    }

    @Override
    public boolean isCellEditable(int rowIndex, int columnIndex) {
        return false;
    }

    @Override
    public Object getValueAt(int rowIndex, int columnIndex) {
        return data[rowIndex][columnIndex];
    }

    @Override
    public void setValueAt(Object aValue, int rowIndex, int columnIndex) {
        data[rowIndex][columnIndex] = aValue;
    }

    @Override
    public void addTableModelListener(TableModelListener l) {

    }

    @Override
    public void removeTableModelListener(TableModelListener l) {

    }
}
